/*****************************************************************************
 * decoder_led.c
 *
 * Copyright (C) 2020 Jeasonvor 1101627719@qq.com
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 ****************************************************************************/

/*****************************************************************************
 * Included Files
 ****************************************************************************/
#include "plum_api.h"
#include "hardware/led/led.h"
#include "hardware/decoder/decoder.h"
/*****************************************************************************
 * Trace Definitions
 ****************************************************************************/
#define LOG_RUN_LEVEL LOG_LEVEL_DEBUG
#define LOG_MODULE    "led.decoder"
#include "thirdparty/log/log.h"
/*****************************************************************************
 * Pre-processor Definitions
 ****************************************************************************/

/*****************************************************************************
 * Private Types
 ****************************************************************************/

/*****************************************************************************
 * Private Function Prototypes
 ****************************************************************************/

/*****************************************************************************
 * Private Data
 ****************************************************************************/

static dev_decoder_pin_t led_pin[] = {
    {
        .pin_a0 = PLUM_HAL_GPIO_ID(A, 1),
        .pin_a1 = PLUM_HAL_GPIO_ID(A, 2),
        .pin_a2 = PLUM_HAL_GPIO_ID(A, 3),
    },
};
/*****************************************************************************
 * Public Data
 ****************************************************************************/

/*****************************************************************************
 * Private Functions
 ****************************************************************************/

/*****************************************************************************
 * Public Functions
 ****************************************************************************/

int led_init(void)
{
    int rc = 0;

    rc = dev_decoder_init(led_pin, PLUM_ARRAY_CNT(led_pin));
    if (rc) {
        LOG_E("dev_decoder_init err,rc:%d", rc);
    }
    return (rc);
}

void led_on(unsigned int idx)
{
    plum_u8 decoder_idx = idx / 8;
    plum_u8 led_idx     = idx % 8;

    switch (led_idx) {
        case 1:
            dev_decoder_write(decoder_idx, 0x00);
            break;
        case 2:
            break;

        case 3:
            break;

        case 4:
            break;

        case 5:
            break;

        case 6:
            break;

        case 7:
            break;

        case 8:
            break;

        default:
            break;
    }
}

void led_off(unsigned int idx)
{
}

/****************************************************************************/
/*                                                                          */
/*  End of file.                                                            */
/*                                                                          */
/****************************************************************************/
